var element, layer;

layui.use(['element', 'layer'], function () {
    element = layui.element;
    layer = layui.layer;
    init();
});

function init() {
    menuInit();
}

//菜单点击
function menuClick(menu) {
    var id = $(menu).attr("attrId");
    var exist = $("li[lay-id='" + id + "']").length;
    if (exist === 0) {
        var href = $(menu).attr("attrHref");
        var name = $(menu).attr("attrName");
        if (href != null && href !== "" && href.length > 1 && href !== "null") {
            element.tabAdd('menubody', {
                title: name
                , content: "<iframe style='width: 100%;height: 800px' src='" + href + "'></iframe>"
                , id: id
            });
        }
    }
    //切换到：用户管理
    element.tabChange('menubody', id);
}

function menuInitByParam(id, href, name) {
    /*判读是否已打开*/
    var exist = $("li[lay-id='" + id + "']").length;
    if (exist === 0) {
        if (href != null && href !== "" && href.length > 1 && href !== "null") {
            element.tabAdd('menubody', {
                title: name
                , content: "<iframe style='width: 100%;height: 800px' src='" + href + "?id=" + id + "'></iframe>"
                , id: id
            });
        }
    }
    //切换到：用户管理
    element.tabChange('menubody', id);
}

function menuInit() {
    var id = "0";
    var href = "amisEditor";
    var name = "Amis可视化编辑器";
    if (href !== "" && href.length > 1 && href !== "null") {
        element.tabAdd('menubody', {
            title: name
            , content: "<iframe style='width: 100%;height: 800px' src='" + href + "'></iframe>"
            , id: id
        });
    }
    //切换到：用户管理
    element.tabChange('menubody', id);
}
